from sqlalchemy import create_engine
from sqlalchemy.ext.automap import automap_base
import pandas as pd
import numpy as np
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import sessionmaker

# engine = create_engine(
#     'mysql+pymysql://oppeincn:nRiQUXpo_E7UO5OrDbhS@10.10.1.102:3306/crm19?charset=utf8'
# )

engine = create_engine(
    "mysql+pymysql://root@127.0.0.1:3306/test?charset=utf8", )

Session = sessionmaker(bind=engine)

session = Session()

Base = declarative_base()


# 创建映射表
class Person(Base):
    __tablename__ = 'userinfo'

    id = Column(Integer, primary_key=True)
    name = Column(String(32))

    def __repr__(self):
        return "<Person(name='%s')>" % self.name


# 创建一个person对象
person = Person(name='张岩林')
# 添加person对象，但是仍然没有提交到数据库
session.add(person)
# 提交数据库
session.commit()

# 添加多条数据
session.add_all([
    Person(name='张岩林'),
    Person(name='aylin')
])
session.commit()

# data = pd.read_sql('select * from `crm_order` limit 10', engine)

# print(data)
